package com.googlecode.agscrum.model.util;

public class Restrictions {

	public static SimpleExpression like(String property, boolean leftSearch,
			String value, boolean rightSearch) {
		if (value == null || value.trim().isEmpty())
			return new SimpleExpression(property, value, " like ");
		else {
			return new SimpleExpression(property, (leftSearch ? "%" : "")
					+ value + (rightSearch ? "%" : ""), " like ");
		}

	}

	public static SimpleExpression ilike(String property, boolean leftSearch,
			String value, boolean rightSearch) {
		if (value == null || value.trim().isEmpty())
			return new SimpleExpression(property, value, " like ");
		else {
			return new SimpleExpression("lower("+property+")", (leftSearch ? "%" : "")
					+ value.toLowerCase() + (rightSearch ? "%" : ""), " like ");
		}

	}

	public static SimpleExpression eq(String property, Object value) {
		return new SimpleExpression(property, value, "=");
	}

}
